package com.situ.day9;

import org.junit.Test;

import java.util.Scanner;

public class OOPDemo {

    @Test
    public void test1() {
        Scanner scanner = new Scanner(System.in);
        int num = 23;
        //studen1: 变量、对象、实例
        Student student1 = new Student();
        //对象.属性
        student1.id = 1;
        student1.name = "zhangsan";
        student1.age = 23;
        student1.gender = "男";
        System.out.println(student1.id);
        System.out.println(student1.name);
        System.out.println(student1.age);

        Student student2 = new Student();
        student2.id = 2;
        student2.name = "lisi";
        student2.age = 24;
        student2.gender = "女";
        System.out.println(student2.name);

        Student[] array = new Student[2];
        array[0] = student1;
        array[1] = student2;
    }

    @Test
    public void test2() {
        Student student = new Student();
        System.out.println(student.id);//0
        System.out.println(student.name);//null
        //System.out.println(student.money);//0.0
    }

    @Test
    public void test3() {
        int[] array1 = new int[3];
        boolean[] array2 = new boolean[3];
        Student[] array3 = new Student[3];
        for (int i : array1) {
            System.out.println(i);
        }
        for (boolean b : array2) {
            System.out.println(b);
        }
        for (Student student : array3) {
            System.out.println(student);
        }
    }

    @Test
    public void test45() {
        int[] array = new int[4];
        array[0] = 33;
        array[1] = 2;
        array[2] = 45;
        array[3] = 19;
        for (int i = 0; i < array.length; i++) {
            //java.lang.ArrayIndexOutOfBoundsException: Index 4 out of bounds for length 4
            System.out.println(array[i]);
        }

        System.out.println(array[4]);
    }

    @Test
    public void test333() {
        Student student = null;
        System.out.println(student);//null
        //NullPointerException
        // null.方法   null.属性
        System.out.println(student.id);
    }

    @Test
    public void test12() {
        //studen1: 变量、对象、实例
        Student student1 = new Student();
        //对象.属性
        student1.id = 1;
        student1.name = "zhangsan";
        student1.age = 23;
        student1.gender = "男";
        //System.out.println(student1.id);
        //System.out.println(student1.name);
        //System.out.println(student1.age);
        //String info1 = student1.getInfo();
        //System.out.println(info1);
        System.out.println(student1.toString());
        //打印对象时候默认调用toString()
        System.out.println(student1);

        Student student2 = new Student();
        student2.id = 2;
        student2.name = "lisi";
        student2.age = 24;
        student2.gender = "女";
        //System.out.println(student2.name);
        //String info2 = student2.getInfo();
        //System.out.println(info2);
        System.out.println(student2.toString());
        System.out.println(student2);
    }

    @Test
    public void test34() {
        Student student1 = new Student();
        student1.id = 1;
        student1.name = "zhangsan";
        student1.age = 223;
        System.out.println(student1.age);
    }

}
